package Connexion;


import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collection;

public class ConnexionMysql extends ConnectionFactory {

	public ConnexionMysql(String host, String user, String mdp, int typeConnection) {
		super(host, user, mdp, typeConnection);
	}

	@Override
	public void connect() {
		try {
			this.connection= DriverManager.getConnection(this.host, this.user, this.mdp);
		} catch (SQLException e) {
			this.connected=false;
			
		}	
	}

	@Override
	public Object getConnection() {
		return connection;
	}

	@Override
	public boolean isConnected() {
		return connected;
	}
 
	@Override
	public void executeQuery(int type, String name, int year, int genre) {
		switch (type){
		
		case 1: rs = mysqlConnector.requeteSelect("call getFilms()", connection);
			break;
		case 2:rs = mysqlConnector.requeteSelect("call ChargerFilm('"+name+"')", connection);
			break;
		case 3:rs = mysqlConnector.requeteSelect("call ChargerFilm('"+name+"')", connection);
			break;
		case 4:rs = mysqlConnector.requeteSelect("call ChargerFilm('"+name+"')", connection);
			break;
		case 5:rs = mysqlConnector.requeteSelect("call CountFilms()", connection);
			break;
		default : 
		
		}
		
	}
	
	public ResultSet getResults(){
		return rs;		
	}
	

}
